<template>
  <div class="container">
    <el-row :gutter="20">
      <el-col :span="10">
        <el-form :model="attendance.workTime">
          <el-form-item label="任务对象：">
            <el-select
              v-model="form.cph"
              placeholder="请选择"
              filterable
              clearable
              @change="$forceUpdate()"
              style="width:400px"
            >
              <el-option
                v-for="item in form.clientList"
                :key="item.index"
                :label="item.NAME"
                :value="item.NAME"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="作业道路：">
            <el-select
              v-model="form.Rname"
              placeholder="请选择"
              @change="$forceUpdate()"
              ref="roadname"
              style="width:400px"
            >
              <el-option
                v-for="(item, index) in form.roadList"
                :value="item.ROADNAME"
                :label="item.ROADNAME"
                :key="index"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="截止时间：">
            <el-date-picker v-model="form.EndDate" type="datetime" value-format="yyyy-MM-dd HH:mm">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="作业内容：" style="height: 230px">
            <el-input
              type="textarea"
              :rows="9"
              v-model="form.guidance"
              placeholder="请输入"
              class="handle-input mr10"
              style="width: 37.5vw; border: 1px solid #a4aca7"
            >
            </el-input>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="6">
        <div class="attendance_btns">
          <el-button type="primary" @click="setWorkingHours"
            >下发任务</el-button
          >
          <!-- <el-button type="danger" @click="closeWorkTime">关 闭</el-button> -->
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'
import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {
    return {
      attendance: {
        workTime: {

          show: false,
          am: [],
          pm: [],
          ClientNo: ''
        }
      },
      form: {
        clientList: [],//车牌号列表
        cph: '',//车牌号
        roadList: [],//作业道路列表
        Rname: '',//作业道路
        alermTypeList: [{ label: '1分钟', value: '1' }, { label: '5分钟', value: '5' }, { label: '10分钟', value: '10' }, { label: '30分钟', value: '30' }],
        alermTypeValue: '5',
        StartDate: formatDate(new Date(new Date().getTime() - 3600 * 1000 * 24), 'yyyy-MM-dd'),
        EndDate: formatDate(new Date(new Date().getTime()), 'yyyy-MM-dd hh:mm'),
      },
      teamValue: '',
      teamList: []
    }
  },
  created () {
    // this.getTeamList();
    // this.openWorkTime();
  },
  mounted () {
    this.getLisencePlateList()
    this.getRoadList()
  },
  methods: {
    async openWorkTime () {
      // this.attendance.workTime.show = true
      // this.attendance.records.show = false
      // 获取时间
      // this.attendance.workTime.am = []
      // this.attendance.workTime.pm = []

      const { data } = await this.$Http.get('DataListCompany/GetWorkeTimeApi?ClientNo=' + localStorage.getItem('CLIENT_NO'))
      // let data = [{"CLIENT_NO":"0000009","CLIENT_NAME":"博德尔清扫队","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090101","CLIENT_NAME":"丰年班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090201","CLIENT_NAME":"华明陈明年班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090202","CLIENT_NAME":"华明陈毅班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090203","CLIENT_NAME":"华明拱富生班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090204","CLIENT_NAME":"华明侯孟余班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090205","CLIENT_NAME":"华明姜炳莲班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090206","CLIENT_NAME":"华明孙克亮班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090207","CLIENT_NAME":"华明孙克文班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090208","CLIENT_NAME":"华明杨霞班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090209","CLIENT_NAME":"华明张彩娥班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090210","CLIENT_NAME":"华明张德栓班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090301","CLIENT_NAME":"华新班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090401","CLIENT_NAME":"金钟崔连顺班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090402","CLIENT_NAME":"金钟郝宝水班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090403","CLIENT_NAME":"金钟郝富刚班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090404","CLIENT_NAME":"金钟孙健班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090405","CLIENT_NAME":"金钟孙学英班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090406","CLIENT_NAME":"金钟魏占庆班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090502","CLIENT_NAME":"开发区南班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090501","CLIENT_NAME":"开发区北班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090601","CLIENT_NAME":"成林道班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090602","CLIENT_NAME":"津滨大道班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090608","CLIENT_NAME":"万新南片班组","AM_IN":"07:00:00","AM_OUT":"11:30:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090603","CLIENT_NAME":"天山南路班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090604","CLIENT_NAME":"东城家园班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090605","CLIENT_NAME":"万新孙建和班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090606","CLIENT_NAME":"百合春天班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090607","CLIENT_NAME":"万新王树友班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090609","CLIENT_NAME":"昆仑路班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090610","CLIENT_NAME":"好新家园班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090611","CLIENT_NAME":"秋丽家园班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090612","CLIENT_NAME":"登州路班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090701","CLIENT_NAME":"张贵庄班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"}]
      this.teamList = data
      this.teamValue = data[0].CLIENT_NO
      this.changClient()
    },
    //获取班组长
    async getLisencePlateList () {
      const { data } = await this.$Http.get('/DataListCompany/GetTeamLeaderListApi?ClientNo=' + localStorage.getItem('CLIENT_NO'))
      this.form.clientList = data
      // this.form.clientList.unshift({ "LicensePlate": "全部" })
    },
    // 获得道路列表
    async getRoadList () {
      var url = "Vehicle/GetAllWorkerRoadInfo?ID=0000009"; // zxdata
      let { data } = await this.$Http.get(url);

      this.form.roadList = data;
      // this.form.Rname = data[0].Rname;
    },
    changClient () {
      this.attendance.workTime.am = []
      this.attendance.workTime.pm = []

      let item = this.teamList.find(val => val.CLIENT_NO == this.teamValue)

      if (!item.AM_IN.split(':')[2]) item.AM_IN += ':00'
      if (!item.AM_OUT.split(':')[2]) item.AM_OUT += ':00'

      this.attendance.workTime.am.push(item.AM_IN, item.AM_OUT)
      this.attendance.workTime.pm.push(item.PM_IN, item.PM_OUT)
    },
    // async getTeamList () {

    //   const { data } = await this.$Http.get('DataListCompany/GetCleanerGroupListApi?ClientNo=' + localStorage.getItem('CLIENT_NO'))

    // },
    // 下发任务
    async setWorkingHours () {
      this.$axios({
        url: 'Vehicle/AddClosedLoopMission',
        method: 'post',
        data: {
          VID: this.form.cph,
          PID: this.form.Rname,
          TIME: this.form.EndDate,
          DETAIL: this.form.guidance,
          TYPE: '2',
          CLIENT_NO: localStorage.getItem('CLIENT_NO_LOGIN')
        },

      }).then((res) => {
        console.log(this.data)
        console.log(res)
        if (res.data.IsSucess) {
          this.$message({
            showClose: true,
            message: '下发成功',
            type: 'success'
          })
        } else {
          this.$message({
            showClose: true,
            message: '下发失败',
            type: 'error'
          })
        }
      })
    },
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
</style>